package com.hb0730.boot.admin.modules.sci.service;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.hb0730.boot.admin.base.R;
import com.hb0730.boot.admin.core.service.BaseServiceImpl;
import com.hb0730.boot.admin.data.domain.BasePage;
import com.hb0730.boot.admin.modules.sci.mapper.SciWorkLearningMapper;
import com.hb0730.boot.admin.modules.sci.model.entity.SciWorkLearning;
import com.hb0730.boot.admin.modules.sci.model.query.SciWorkLearningQuery;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
* @author 31673
* @description 针对表【sci_work(科研学术著作表)】的数据库操作Service实现
* @createDate 2024-10-24 12:39:19
*/
@Slf4j
@Service
public class SciWorkLearningService extends BaseServiceImpl<SciWorkLearningMapper, SciWorkLearning>
    implements IService<SciWorkLearning> {

    public BasePage<SciWorkLearning> queryPage(SciWorkLearningQuery query) {
        Page<SciWorkLearning> page = new Page<>(query.getCurrent(), query.getSize());
        List<SciWorkLearning> vos = this.baseMapper.queryPage(page, query);
        return new BasePage<>(page.getCurrent(), page.getSize(), page.getTotal(), vos);
    }
    @Transactional(rollbackFor = Exception.class)
    public R<SciWorkLearning> saveLearning(SciWorkLearning sciWorkLearning) {
        super.save(sciWorkLearning);
        return R.OK(sciWorkLearning);
    }

    public R<String> deleteByIds(List<String> ids) {
        if (CollectionUtil.isEmpty(ids)) {
            return R.NG("参数不能为空");
        }
        removeByIds(ids);
        return R.OK();
    }

    public R<SciWorkLearning> updateById(String id, SciWorkLearning sciWorkLearning) {
        SciWorkLearning sciWorkLearning0 = getById(id);
        if (null == sciWorkLearning0) {
            return R.NG("用户不存在");
        }
        updateById(sciWorkLearning);
        return R.OK(sciWorkLearning);
    }
}




